package com.system.manager.modules.projectLibrary.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.projectLibrary.entity.Project;
import com.system.manager.modules.projectLibrary.entity.ProjectChange;
import com.system.manager.modules.projectLibrary.entity.ProjectRecord;
import com.system.manager.modules.projectLibrary.service.IProjectChangeService;
import com.system.manager.modules.projectLibrary.service.IProjectRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jisf
 * @since 2021-11-10
 */
@Api(tags = "项目记录API")
@RestController
@RequestMapping("/projectLibrary/project-record")
public class ProjectRecordController {

    @Autowired
    private IProjectRecordService iProjectRecordService;

    @ApiOperation("插入项目记录")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @PostMapping("/insert/projectRecord")
    public Result insertProjectRecord(@RequestBody ProjectRecord projectRecord){
        try {
            iProjectRecordService.insertProjectRecord(projectRecord);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }

    @ApiOperation("修改项目记录")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @PostMapping("/update/projectRecord")
    public Result updateProjectRecord(@RequestBody ProjectRecord projectRecord){
        try {
            iProjectRecordService.updateProjectRecord(projectRecord);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }

}
